package com.zy.order.exception;


import com.zy.order.vo.ResultVO;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * description 全局异常处理类
 *
 * @author ZY
 * @date 2021-03-06 15:02:24
 **/
@ControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 处理自定义异常
     */
    @ExceptionHandler(value = DefinitionException.class)
    @ResponseBody
    public ResultVO<?> definitionExceptionHandler(DefinitionException e) {
        return ResultVO.getError(e.getErrorCode(), e.getErrorMsg());
    }

    /**
     * 处理其他异常
     */
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public ResultVO<?> exceptionHandler(Exception e) {
        e.printStackTrace();
        return ResultVO.getServerError(MessageCode.SYSTEM_BUSY.getMessage());
    }
}